/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systemsim;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.*;
import javax.swing.border.Border;


/**
 *
 * @author emil
 */
public class GUIKitchen {
    
    JFrame guiKitchen;
    Container contentPane;
    
    private HashMap<Kitchen.FoodOrder, JPanel> groupsInLine = new HashMap<Kitchen.FoodOrder, JPanel>();
    
    public GUIKitchen()
    {
        guiKitchen = new JFrame("Kitchen   Current Load = 0 Plates");
        guiKitchen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        guiKitchen.setSize(1280, 80);
        guiKitchen.setBounds(0, 0, 1280, 80);
        guiKitchen.setResizable(false);
        guiKitchen.setLocation(0, 780);
        guiKitchen.setAlwaysOnTop(true);
 
        //Set up the content pane.
        contentPane = guiKitchen.getContentPane();
        BoxLayout layout = new BoxLayout(contentPane, BoxLayout.LINE_AXIS);
        contentPane.setLayout(layout);
        contentPane.setSize(1280, 80);
        
        guiKitchen.setVisible(true);
        
    }
    
    public synchronized void add(Kitchen.FoodOrder fd)
    {
        //System.out.println("REPAINT");
        Color color = Color.GREEN;
        if(fd.group.getID()%2 == 0)
        {
            color = Color.ORANGE;
        }
        
        JPanel p = new JPanel();
        p.setSize(80, 80);
        p.setPreferredSize(new Dimension(80,80));
        p.setMaximumSize(new Dimension(80,80));
        BoxLayout l = new BoxLayout(p, BoxLayout.PAGE_AXIS);
        p.setLayout(l);
        //p.setAlignmentY(p.);
        
        Border loweredbevel = BorderFactory.createLoweredBevelBorder();
        Border raisedbevel = BorderFactory.createRaisedBevelBorder();
        p.setBorder(BorderFactory.createCompoundBorder(raisedbevel, loweredbevel));
        
    
        p.setBackground(color);
        JLabel guiGroup = new JLabel("Group: "+ fd.group.getID());
        //item.setAlignmentX(0.5F);;
        guiGroup.setSize(80, 80);
        guiGroup.setBackground(color);
        //item.setBackground(Color.RED);
        guiGroup.setOpaque(true);
        p.add(guiGroup);
        
//        guiGroup = new JLabel("numPpl: "+group.getNumPeople());
//        guiGroup.setSize(80, 80);
//        guiGroup.setBackground(color);
//        guiGroup.setOpaque(true);
//        p.add(guiGroup);
        
        p.setVisible(true);
        
        this.groupsInLine.put(fd, p);
        contentPane.add(p);
        
        p.revalidate();
        guiKitchen.validate();
        
        contentPane.repaint();
        guiKitchen.repaint();
        
        //System.out.println("REPAINT");
    }
    
    public synchronized void remove(Kitchen.FoodOrder fd)
    {
        JPanel toRemove;
        
        toRemove = this.groupsInLine.remove(fd);
        
        contentPane.remove(toRemove);
        contentPane.validate();
        guiKitchen.validate();
        
        contentPane.repaint();
        guiKitchen.repaint();
        
        
        
        
    }
    
    public  void setSizeDisplay(int size)
    {
        guiKitchen.setTitle("Kitchen   Current Load = "+groupsInLine.size()+" Plates");  
    }
   
    public static void main(String[] args)
    {
       
        
        
//        JLabel item = new JLabel("Group");
//        item.setSize(80, 80);
//        item.setMaximumSize(new Dimension(80,80));
//        
//        contentPane.add(item);
//        
//        contentPane.add(Box.createRigidArea(new Dimension(5, 0)));
//        JPanel p = new JPanel();
//        p.setSize(80, 80);
//        p.setPreferredSize(new Dimension(80,80));
//        p.setMaximumSize(new Dimension(80,80));
//        p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
        



        
    }
}
